import unittest
from app import create_app
from main import app


class MyTestCase(unittest.TestCase):
    def setUp(self):
        """在每个测试前执行"""
        app.config['TESTING'] = True  # 进入测试模式
        self.app = create_app()
        self.client = self.app.test_client()

    def test_ping(self):
        """测试 /ping 路由"""
        response = self.client.get('/ping')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, {"message": "pong!"})


if __name__ == '__main__':
    unittest.main()
